package com.squirrel.michale;

import java.util.Arrays;

/**
 * @author guanhao 观浩
 * @version 1.0.0.0
 * @createTime 2023/2/7 7:26 AM
 * @company Michale Squirrel
 * @link
 * @description
 */
public class LeetCode2559_2 {

    public int[] vowelStrings(String[] words, int[][] queries) {

        int count = 0;
        int[] vowelStringCount = new int[words.length];
        for (int i = 0; i < words.length; i++) {
            char[] chars = words[i].toCharArray();
            if (isVowel(chars[0]) && isVowel(chars[chars.length - 1])) {
                count++;
            }
            vowelStringCount[i] = count;
        }

        int[] result = new int[queries.length];
        for (int i = 0; i < queries.length; i++) {
            int[] queryArray = queries[i];
            if (queryArray[0] == 0) {
                result[i] = vowelStringCount[queryArray[1]];
            } else {
                result[i] = vowelStringCount[queryArray[1]] - vowelStringCount[queryArray[0]-1];
            }
        }
        return result;
    }

    public boolean isVowel(char vowel) {
        return vowel == 'a' || vowel == 'e' || vowel == 'i' || vowel == 'o' || vowel == 'u';
    }


    public static void main(String[] args) {
        String[] words =new String[] {"aba","bcb","ece","aa","e"};
        int[][] queries = new int[][]{{0, 2}, {1, 4}, {1, 1}};

        LeetCode2559_2 leetCode2559 = new LeetCode2559_2();
        System.out.println(Arrays.toString(leetCode2559.vowelStrings(words, queries)));
    }
}
